package com.ad.backstage.controller;


import com.ad.backstage.service.ItemSystemService;
import com.ad.payload.dto.item.*;
import com.ad.payload.model.IdDto;
import com.ad.payload.model.PageView;
import com.ad.payload.model.ResultBean;
import com.ad.payload.vo.item.ItemCategoryVo;
import com.ad.payload.vo.item.ItemDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @author:dxgong
 * @日期 2021/3/28 10:12
 * @注释
 */
@RestController
@RequestMapping("ItemController")
public class ItemController {

    @Autowired
    private ItemSystemService itemSystemService;

    /**
     * 分页产品类目
     *
     * @param itemCategorySearchDto
     * */
    @PostMapping("/back/auth/pageItemCategory")
    public PageView<ItemCategoryVo> pageItemCategory(@RequestBody @Valid ItemCategorySearchDto itemCategorySearchDto){
        return itemSystemService.pageItemCategory(itemCategorySearchDto);
    }


    /**
     * 添加产品类目
     *
     * @param itemCategoryAddDto
     * */
    @PostMapping("/back/auth/addItemCategory")
    public ResultBean<String> addItemCategory(@RequestBody @Valid ItemCategoryAddDto itemCategoryAddDto){
        return ResultBean.success(itemSystemService.addItemCategory(itemCategoryAddDto));
    }


    /**
     * 更新产品类目
     *
     * @param itemCategoryEditDto
     * */
    @PostMapping("/back/auth/editItemCategory")
    public ResultBean<String> updateItemCategory(@RequestBody @Valid ItemCategoryEditDto itemCategoryEditDto){
        return ResultBean.success(itemSystemService.updateItemCategory(itemCategoryEditDto));
    }


    /**
     * 删除产品类目
     *
     * @param idDto
     */
    @PostMapping("/back/auth/deleteItemCategory")
    public Long deleteItemCategory(@RequestBody @Valid IdDto idDto) {
        return itemSystemService.deleteItemCategory(idDto);
    }


    /**
     * 根据id查询产品类目
     *
     * @param idDto
     * */
    @PostMapping("/back/auth/queryItemCategoryById")
    public ItemCategoryVo queryItemCategoryById(@RequestBody @Valid IdDto idDto){
        return itemSystemService.queryItemCategoryById(idDto);
    }


    /**
     * 分页查询产品
     *
     * @param itemDetailSearchDto
     * */
    @PostMapping("/back/auth/pageItemDetailVo")
    public PageView<ItemDetailVo> pageItemDetailVo(@RequestBody @Valid ItemDetailSearchDto itemDetailSearchDto){
        return itemSystemService.pageItemDetailVo(itemDetailSearchDto);
    }


    /**
     * 新增产品
     *
     * @param itemDetailAddDto
     * */
    @PostMapping("/back/auth/insertItemDetail")
    public Long insertItemDetail(@RequestBody @Valid ItemDetailAddDto itemDetailAddDto){
        return itemSystemService.insertItemDetail(itemDetailAddDto);
    }


    /**
     * 更新产品
     *
     * @param itemDetailEditDto
     * */
    @PostMapping("/back/auth/updateItemDetail")
    public Long updateItemDetail(@RequestBody @Valid ItemDetailEditDto itemDetailEditDto){
        return itemSystemService.updateItemDetail(itemDetailEditDto);
    }


    /**
     * 删除产品
     *
     * @param idDto
     * */
    @PostMapping("/back/auth/deleteItemDetail")
    public Long deleteItemDetail(@RequestBody @Valid IdDto idDto){
        return itemSystemService.deleteItemDetail(idDto);
    }


    /**
     * 根据id查询产品
     *
     * @param idDto
     * */
    @PostMapping("/back/auth/selectItemDetailById")
    public ItemDetailVo selectItemDetailById(@RequestBody @Valid IdDto idDto){
        return itemSystemService.selectItemDetailById(idDto);
    }


}
